package tests.model_tests;

import org.junit.*;
import static org.junit.Assert.*;
import application.models.datalayer.*;

public class Date_test {
	
	private long timeLong_negative = -100, timeLong_positive = 100, timeLong = 0;
	private String timeString_negative = "-100", timeString_positive = "100", timeString = "0";
	private java.util.Date dateSuper_negative = new Date(timeLong_negative), dateSuper_positive = new Date(timeLong_positive), dateSuper = new Date(timeLong);
	
	/**
	 * Tested for positive and negative real values, and zero.
	 * For non-empty strings and empty strings.	 
	 * 
	 * Positive tests:
	 * Test that the two constructors from Date and the constructor from 	          	 
	 * java.util.Date are equal in their toString() methods.
	 * 
	 * Negative tests:
	 * Test that no two different Date/java.util.Date objects toString() methods 		 
	 * return equal values, and that an empty string in the constructor will throw an exception.
	 */
	@Test
	public void test(){
		
		boolean emptyStringPass = false;
		
		Date dateLong_negative = new Date(timeLong_negative);
		Date dateString_negative = new Date(timeString_negative);
		
		Date dateLong_positive = new Date(timeLong_positive);
		Date dateString_positive = new Date(timeString_positive);
		
		Date dateLong = new Date(timeLong);
		Date dateString = new Date(timeString);
		
		// positive:
		// tests that the objects created with similar long and string values return 		
		// equal strings with the .tostring() method call. And that the .toString() 		
		// calls for the date objects created with a long parameter and string 			
		// parameter equals that of the java.util.Date object. 
		
		assertEquals(dateLong_negative.toString(), dateString_negative.toString());
		assertEquals(dateLong_negative.toString(), dateSuper_negative.toString());
		assertEquals(dateString_negative.toString(), dateSuper_negative.toString());
		
		assertEquals(dateLong_positive.toString(), dateString_positive.toString());	
		assertEquals(dateLong_positive.toString(), dateSuper_positive.toString());
		assertEquals(dateString_positive.toString(), dateSuper_positive.toString());
		
		assertEquals(dateLong.toString(), dateString.toString());
		assertEquals(dateLong.toString(), dateSuper.toString());
		assertEquals(dateString.toString(), dateSuper.toString());
		
		// negative:
		// tests that no .toString() calls on different date object are considered equal, 
		// and that calling the Date constructor with an empty string will throw an exception.
		assertFalse(dateLong_negative.toString().equals(timeString));
		assertFalse(dateString_negative.toString().equals(timeString));
		
		assertFalse(dateLong_positive.toString().equals(timeString));
		assertFalse(dateString_positive.toString().equals(timeString));
		
		assertFalse(dateLong.toString().equals(timeString_negative));
		assertFalse(dateString.toString().equals(timeString_negative));	
		
		try{
			new Date("");
		}catch(NumberFormatException e){
			emptyStringPass = true;// This is supposed to happen
		}
		if(!emptyStringPass){
			fail();
		}
	}
}
